﻿using System;
using System.Configuration;
using System.Linq;
using Controllers;

namespace Web
{
    public partial class QuestionList : System.Web.UI.Page
    {
        protected Pagination Model;
        protected string noDisplay = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Model = new Pagination();
            Model.PageNumShown = 6;
            Model.CurrentPage = 1;
            Model.NumPerPage = 10;
            //EmpBasicInfo ebi = Session["ebi"] as EmpBasicInfo;
            if (Request.QueryString["pageNum"] != null)
            {
                Model.CurrentPage = int.Parse(Request.QueryString["pageNum"]);
            }
            if (Request.QueryString["numPerPage"] != null)
            {
                Model.NumPerPage = int.Parse(Request.QueryString["numPerPage"]);
            }
            string typeId = Request.QueryString["typeId"];
            ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
            int sNum = (Model.CurrentPage - 1) * Model.NumPerPage + 1;
            int eNum = Model.CurrentPage * Model.NumPerPage;
            string strSql = string.Format(@"select Id,TypeId,QuestionType,Question,Options,Answer from(
SELECT ROW_NUMBER() over(order by Id) rowNum,Id,TypeId,QuestionType,Question,Options,Answer
  FROM ExamQuestions
  where TypeId={0}
  ) t where rowNum between {1} and {2};",typeId, sNum, eNum);
            string strSql2 = string.Format(@"select COUNT(0) from ExamQuestions where TypeId={0};", typeId);
            var list = ctx.ExecuteQuery<ExamQuestion>(strSql);
            rptList.DataSource = list;
            rptList.DataBind();

            var list2 = ctx.ExecuteQuery<int>(strSql2);
            Model.TotalCount = list2.First();
        }
    }
}